package com.sts.source.model;

import com.sts.jdbc.model.JdbcConnectionInfo;
import com.sts.source.StsSource;
import com.sts.source.impl.JdbcSourceImpl;
import lombok.Getter;
import lombok.Setter;

import java.util.List;

@Getter
@Setter
public class JdbcSourceConfig extends BaseSourceConfig {

    private JdbcConnectionInfo jdbcConnectionInfo;
    private String selectSql;
    private int fetchSize = 1;

    // 文件有头
    public JdbcSourceConfig(JdbcConnectionInfo jdbcConnectionInfo, String selectSql) {
        this.jdbcConnectionInfo = jdbcConnectionInfo;
        this.selectSql = selectSql;
    }

    public JdbcSourceConfig(JdbcConnectionInfo jdbcConnectionInfo, String selectSql, int fetchSize) {
        this.jdbcConnectionInfo = jdbcConnectionInfo;
        this.selectSql = selectSql;
        this.fetchSize = fetchSize;
    }

    // 文件没有头
    public JdbcSourceConfig(boolean hasHeader, List<String> headerList, JdbcConnectionInfo jdbcConnectionInfo, String selectSql) {
        super(hasHeader, headerList);
        this.jdbcConnectionInfo = jdbcConnectionInfo;
        this.selectSql = selectSql;
    }

    public JdbcSourceConfig(boolean hasHeader, List<String> headerList, JdbcConnectionInfo jdbcConnectionInfo, String selectSql, int fetchSize) {
        super(hasHeader, headerList);
        this.jdbcConnectionInfo = jdbcConnectionInfo;
        this.selectSql = selectSql;
        this.fetchSize = fetchSize;
    }

    @Override
    public StsSource buildImpl() {
        return new JdbcSourceImpl(this);
    }
}
